package com.downhometech.productcalculator.controllers;

import java.util.ArrayList;
import java.util.List;

import com.downhometech.productcalculator.models.CartItem;
import com.squareup.android.Bill;
import com.squareup.android.Currency;
import com.squareup.android.LineItem;
import com.squareup.android.Square;

import android.app.Activity;
import android.content.Context;

public class SquareIntegration 
{
	private Activity activity = null;
	private Square square = null;
	private Bill.Builder order = new Bill.Builder() ;
	
	public SquareIntegration(Activity activity) 
	{
		this.activity = activity;
		this.square = new Square(this.activity);
	}
	
	public boolean isSquareInstalled() 
	{
		return square.installationStatus() == Square.InstallationStatus.AVAILABLE;
	}
	
	public void addCart(String description, double total)
	{
		int price = new Double((total * 100)).intValue();
		LineItem squareLine = new LineItem.Builder().price(price, Currency.USD).description(description).build();
		order.add(squareLine);
	}
	
	/*
	public void addItem(CartItem item)
	{
		double quantity = item.getQuantity();
		String description = item.getProduct().getName();
		if (quantity > 1) { description += " x" + quantity; }
		int price = new Double((item.getProduct().getPrice() * 100) * quantity).intValue();
		LineItem squareLine = new LineItem.Builder().price(price, Currency.USD).description(description).build();
		//order.add(squareLine);
	}
	
	public void addTotal(String description, double total)
	{
		int price = new Double(total * 100).intValue();
		LineItem squareLine = new LineItem.Builder().price(price, Currency.USD).description(description).build();
		 //new Bill.Builder().add(squareLine);		
	}
	*/
	public void checkOutWithSquare()
	{
		Bill bill =  order.build();
		List<LineItem> lineItems = bill.lineItems();
		for (int x=0; x<lineItems.size(); x++) { System.out.println(lineItems.get(x)); }
		square.squareUp(bill);
	}
}
